﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LuKou.Shopspace.Domains;
using LuKou.Shopspace.Services;

using LuKou.Web.BLL.Extensions;

namespace LuKou.Web.BLL.Service
{
    public class GoodsOrdersService
    {
        private static IGoodsOrdersSvr _svr;
        static GoodsOrdersService()
        {
            _svr = ServiceHelper.Get<IGoodsOrdersSvr>("IGoodsOrdersSvr");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        /// <param name="pageSize"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public static PagedList<GoodsOrders> GetGoodsOrdersList(long userId, int index, int pageSize, string order)
        {
            return GetGoodsOrdersList(userId, null, index, pageSize, order);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="code"></param>
        /// <param name="index"></param>
        /// <param name="pageSize"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public static PagedList<GoodsOrders> GetGoodsOrdersList(long userId, string code, int index, int pageSize, string order)
        {
            if (index < 1) index = 1;
            if (pageSize < 1) pageSize = 1;
            GoodsOrdersQueryParam param = new GoodsOrdersQueryParam();
            param.AddParamOfAgentsUserID(userId);
            if (!string.IsNullOrEmpty(code))
            {
                param.AddParamOfCode(code);
            }
            List<GoodsOrders> result = _svr.GetGoodsOrdersList(param, true, pageSize * (index - 1), pageSize).Cast<GoodsOrders>().ToList();
            return new PagedList<GoodsOrders>(result, index, pageSize, _svr.GetGoodsOrdersCount(param));
        }

        public static IList<GoodsOrdersItem> GetGoodsOrdersItemList(string code)
        {
            GoodsOrdersItemQueryParam param = new GoodsOrdersItemQueryParam();
            param.AddParamOfOrdersCode(code);
            return _svr.GetGoodsOrdersItemList(param, true, 0, _svr.GetGoodsOrdersItemCount(param)).Cast<GoodsOrdersItem>().ToList();
        }
    }
}
